package com.bjtu.laorenyouhao.event.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.event.dao.EventInfoDao;
import com.bjtu.laorenyouhao.event.entity.EventInfoEntity;
import com.bjtu.laorenyouhao.event.service.EventInfoService;
import org.springframework.util.StringUtils;


@Service("eventInfoService")
public class EventInfoServiceImpl extends ServiceImpl<EventInfoDao, EventInfoEntity> implements EventInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        String key = (String) params.get("key");
        QueryWrapper<EventInfoEntity> queryWrapper = new QueryWrapper<EventInfoEntity>();
        if (StringUtils.hasLength(key)){

            if (key.equals("抓拍高兴")){
                queryWrapper.eq("event_type",0);
            } else if (key.equals("陌生人出现")) {
                queryWrapper.eq("event_type",1);
            } else if (key.equals("摔倒")) {
                queryWrapper.eq("event_type",2);
            } else if (key.equals("义工距离过近")) {
                queryWrapper.eq("event_type",3);
            } else if (key.equals("进入禁止区域")) {
                queryWrapper.eq("event_type",4);
            } else {
                queryWrapper.like("event_date",key).or().eq("id",key);
            }
        }


        IPage<EventInfoEntity> page = this.page(
                new Query<EventInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}